import 'dart:developer';

import 'package:shop/routers/Router.dart';

///全局异常处理 比如返回状态为102 自动跳转到登录页等
class BaseError {
  BaseError(Object error, StackTrace stackTrace) {
    this._reportError(error, stackTrace);
  }

  _reportError(Object error, StackTrace stackTrace) {
    if (error is BaseException) {
      BaseException err = error;
      switch (err.code) {
        case "102":
          log("跳转到登录界面");
          route.pushNamed(MyRoutes.codeLogin);
          break;
        case "801":
          break;
        case "100":
          break;
        default:
          log("未处理的自定义异常!");
      }
    } else {
      print(error);
      print(stackTrace);
    }
  }
}

class BaseException implements Exception {
  String code;
  String msg;
  BaseException(this.code, this.msg);
  @override
  String toString() => "code: $code , msg: $msg";
}
